home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / phillips / ilabel.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-29  |  3.7 KB  |  155 lines

  1. #include "cips.h"
  2.  
  3. #define R             9
  4. #define C             7
  5. #define COUNTER_LIMIT 8
  6. #define IE_START      7
  7. #define VAL         200
  8.  
  9. short image[ROWS][COLS];
  10.  
  11.          /******************************
  12.          *
  13.          *   Define all the 9x7 arrays
  14.          *   that contain the characters.
  15.          *
  16.          *******************************/
  17.  
  18. /*
  19. NOTE: four dots (....) represents
  20. portions of code omitted from this
  21. printed listing -mb
  22. */
  23.  
  24.                ....    
  25.  
  26. short aa[R][C] = 
  27.    { {  0,  0,  0,  0,  0,  0,  0},
  28.      {  0,  0,  0,VAL,  0,  0,  0},
  29.      {  0,  0,VAL,  0,VAL,  0,  0},
  30.      {  0,VAL,  0,  0,  0,VAL,  0},
  31.      {  0,VAL,VAL,VAL,VAL,VAL,  0},
  32.      {  0,VAL,  0,  0,  0,VAL,  0},
  33.      {  0,VAL,  0,  0,  0,VAL,  0},
  34.      {  0,VAL,  0,  0,  0,VAL,  0},
  35.      {  0,  0,  0,  0,  0,  0,  0}};
  36.  
  37.                ....
  38.  
  39. short az[R][C] = 
  40.    { {  0,  0,  0,  0,  0,  0,  0},
  41.      {  0,VAL,VAL,VAL,VAL,VAL,  0},
  42.      {  0,  0,  0,  0,  0,VAL,  0},
  43.      {  0,  0,  0,  0,VAL,  0,  0},
  44.      {  0,  0,  0,VAL,  0,  0,  0},
  45.      {  0,  0,VAL,  0,  0,  0,  0},
  46.      {  0,VAL,  0,  0,  0,  0,  0},
  47.      {  0,VAL,VAL,VAL,VAL,VAL,  0},
  48.      {  0,  0,  0,  0,  0,  0,  0}};
  49.  
  50.                ....
  51.  
  52. main(argc, argv)
  53.    int  argc;
  54.    char *argv[];
  55. {
  56.    int    l=1, w=1;
  57.    int    counter=0, i, j, il, ie=7, ll, le;
  58.    struct tiff_header_struct image_header;
  59.  
  60.    my_clear_text_screen();
  61.  
  62.    if(argc < 4){
  63.       printf("\n usage: ilabel file-name il text\n");
  64.       exit(-1);
  65.    }
  66.  
  67.          /******************************
  68.          *
  69.          *   Setup the output file.
  70.          *
  71.          *******************************/
  72.  
  73.    image_header.lsb            = 1;
  74.    image_header.bits_per_pixel = 8;
  75.    image_header.image_length   = l*ROWS;
  76.    image_header.image_width    = w*COLS;;
  77.    image_header.strip_offset   = 1000;
  78.  
  79.    if(does_not_exist(argv[1]))
  80.       create_allocate_tiff_file(argv[1], 
  81.                                 &image_header, 
  82.                                 image);
  83.    else
  84.       read_tiff_image(argv[1], image, 1, 1, 
  85.                       ROWS, COLS);
  86.  
  87.    il = atoi(argv[2]);
  88.  
  89.          /******************************
  90.          *
  91.          *   Loop through the text
  92.          *   arguments and place the
  93.          *   letter arrays into the
  94.          *   image.
  95.          *
  96.          *******************************/
  97.  
  98.    printf("\n");
  99.    for(i=3; i<argc; i++){
  100.       for(j=0; j<(strlen(argv[i])); j++){
  101.  
  102.          printf("%c", argv[i][j]);
  103.          if(argv[i][j] == 'a')
  104.             copy_array_into_image(aa, image, il, ie);
  105.          if(argv[i][j] == 'b')
  106.             copy_array_into_image(ab, image, il, ie);
  107.          if(argv[i][j] == 'c')
  108.             copy_array_into_image(ac, image, il, ie);
  109.  
  110.                 ....
  111.  
  112.          if(argv[i][j] == 'z')
  113.             copy_array_into_image(az, image, il, ie);
  114.  
  115.                 ....
  116.  
  117.  
  118.          ie = ie + C;
  119.          counter++;
  120.          if(counter > COUNTER_LIMIT){
  121.             ie      = IE_START;
  122.             il      = il+R+1;
  123.             counter = 0;
  124.          }
  125.       }  /* ends loop over letters in argument */
  126.          copy_array_into_image(xx, image, il, ie);
  127.          ie = ie + C;
  128.          counter++;
  129.          if(counter > COUNTER_LIMIT){
  130.             ie      = IE_START;
  131.             il      = il+R+1;
  132.             counter = 0;
  133.          }
  134.    }  /* ends loop over arguments */
  135.  
  136.    il = 1;
  137.    ie = 1;
  138.    write_array_into_tiff_image(argv[1], image,
  139.                                il, ie,
  140.                                il+ROWS, ie+COLS);
  141. }
  142.  
  143.  
  144. copy_array_into_image(a, the_image, il, ie)
  145.    short a[R][C], the_image[ROWS][COLS];
  146.    int   il, ie;
  147. {
  148.    int i, j;
  149.    for(i=0; i<R; i++)
  150.       for(j=0; j<C; j++)
  151.          the_image[il+i][ie+j] = a[i][j];
  152.  
  153. }  /* ends copy_array_into_image */
  154. 
  155.